package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Supplierorder;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.SupplierorderService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 supplierorderController
@RequestMapping("/supplierorderController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /supplierorderController
public class SupplierorderController {
	@Resource
    SupplierorderService supplierorderService;
	@RequestMapping("/getAllSupplierorder")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Supplierorder> getAllSupplierorder() throws Exception{
    	System.out.println("查询管理员");
    	return supplierorderService.getAllSupplierorders();
    }
	@RequestMapping("/addSupplierorder")
	@ResponseBody
	public DTO<Supplierorder> addSupplierorder(@RequestBody Supplierorder supplierorder) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加管理员成功");
		return supplierorderService.addSupplierorder(supplierorder);
	}

	@RequestMapping("/deleteSupplierorderByUsno/{usno}")
	@ResponseBody
    public DTO<Supplierorder> deleteSupplierorderByUsno(@PathVariable("usno") String usno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(usno+"删除管理员成功");
    	return supplierorderService.deleteSupplierorderByUsno(usno);
    }



	@RequestMapping("/getSupplierorderByUsno/{usno}")
	@ResponseBody
	public DTO<Supplierorder> getSupplierorderByUsno(@PathVariable("usno") String usno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(usno+"根据主键查询管理员成功");
		return supplierorderService.getSupplierorderByUsno(usno);
	}

	@RequestMapping("/updateSupplierorderByUsno")
	@ResponseBody
	public DTO<Supplierorder> updateSupplierorderByUsno(@RequestBody Supplierorder supplierorder) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改管理员成功");
		System.out.println(supplierorder);
		return supplierorderService.updateSupplierorderByUsno(supplierorder);
	}

	@RequestMapping("/getSupplierorderByPage")
	@ResponseBody
	public DTO<Supplierorder> getSupplierorderByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		String cacheId = "SupplierorderByPage" + pageInfo.getCurrPage();//自编redis每页数据缓存的key
		return pageInfo.getCurrPage() > 2 ? supplierorderService.getSupplierorderByPage(pageInfo) :
				supplierorderService.getSupplierorderByPage(pageInfo,cacheId);
	}

}
